<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<form>
    id:<input type="text" name="id" v-model="emp.id" readonly><br>
    名字: <input type="text" name="name"  v-model="emp.name"><br>
    工作: <input type="text" name="job"  v-model="emp.job"><br>
    工资: <input type="text" name="sal"  v-model="emp.sal"><br>
    <input type="button" value="修改" @click="update()">
</form>

<!--引入axios和vue-->
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.14/vue.js"></script>

<script>
    let v = new Vue({
        el:"form",
        data:{
            emp:{}
        },
        methods:{
            update:function () {
                //获取表单中的数据
               //let data = new FormData(document.querySelector("form"));
               axios.post("/update",v.emp).then(function () {
                   alert("修改完成");
                   location.href="/select.html";
               })
            }
        },
        created: function () {
            //得到地址栏上的id
            let id = location.search.split("=")[1];
            console.log(id);
            axios.get("/selectById?id="+id).then(function (respoonse) {
                v.emp = respoonse.data;
            })
        }
    })
</script>

</body>
</html>